<template>
  <div class="qualityList">
    <el-table :data="tableData" border height="700" style="margin-top: 20px;">
      <el-table-column label="序号" width="80" >
        <template slot-scope="scope">{{ (pageInfo.pageNo - 1) * pageInfo.pageSize + scope.$index + 1 }}</template>
      </el-table-column>
      <!--<el-table-column label="透明度(cm)" prop="transparency"></el-table-column>-->
      <el-table-column label="PH" prop="ph"></el-table-column>
      <el-table-column label="溶解氧(mg／L)" prop="dissolvedOxygen"></el-table-column>
      <el-table-column label="氨氮(mg／L)" prop="ammoniaNitrogen"></el-table-column>
      <el-table-column label="亚硝酸盐(mg／L)" prop="nitrite"></el-table-column>
      <!--<el-table-column label="硫化氢(mg／L)" prop="hydrogen"></el-table-column>-->
      <el-table-column label="自测时间" prop="createTime"></el-table-column>
      <el-table-column label="测试人员" prop="accountNo" :v-if="idAdmin"></el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <i class="el-icon-delete actionIcon" style="color: #f56c6c;"  @click="handleDelete(scope.row.id)"></i>
        </template>
      </el-table-column>
    </el-table>
    
    <div style="margin-top: 20px;">
      <el-pagination
        background
        :current-page="pageInfo.pageNo"
        :page-size="pageInfo.pageSize"
        layout="total, prev, pager, next, jumper"
        :total="pageInfo.total"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
</template>

<script>
import { deleteQualityById, getQualityPage } from '@/api/quality'

export default {
  name: 'qualityList',
  data() {
    return {
      content: '',
      tableData: [],
      pageInfo: {
        pageNo: 1,
        pageSize: 10,
        total: 0
      }
    }
  },
  computed: {
    idAdmin() {
      const value = localStorage.getItem('account')
      return value && value === 'admin'
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    getList() {
      const payload = {
        pageNo: this.pageInfo.pageNo,
        pageSize: this.pageInfo.pageSize,
        content: this.content,
      }
      getQualityPage(payload).then(res => {
        console.log(res)
        this.tableData = res.records
        this.pageInfo.total = res.total
      })
    },
    handleDelete(id) {
      this.$confirm('确认删除当前数据吗？').then(_ => {
        deleteQualityById(id).then(res => {
          this.getList()
        })
      }).catch(_ => {})
    },
    handleCurrentChange(pageNo) {
      this.pageInfo.pageNo = pageNo;
      this.getList()
    }
  }
}
</script>

<style lang="scss" scoped>
.qualityList {
  padding: 20px;
  .actionIcon {
    font-size: 18px;
    cursor: pointer;
  }
}
</style>